package com.school.movie.common.config;

import com.school.movie.common.component.WebSocket;
import com.school.movie.common.interceptor.WebSocketHanShakeInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

import javax.inject.Inject;

/**
 * @author swift
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Inject
    private WebSocket webSocket;

    @Inject
    private WebSocketHanShakeInterceptor interceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(webSocket, "/mobile/connect/websocket")
                .setAllowedOrigins("*")
                .addInterceptors(interceptor);
    }


}